import $ from 'jquery'

			var version="1.0.0.0"
			var ServiceUrl = "http://127.0.0.1:90/MyServices/MyTestService/Jweb/{0}?jsoncallback=?";
			//var ServiceUrl = "http://127.0.0.1:9000/WebSrv.svc/Jweb/{0}?jsoncallback=?";
			$.format = function (source, params) {
			    if (arguments.length == 1)
			        return function () {
			            var args = $.makeArray(arguments);
			            args.unshift(source);
			            return $.format.apply(this, args);
			        };
			    if (arguments.length > 2 && params.constructor != Array) {
			        params = $.makeArray(arguments).slice(1);
			    }
			    if (params.constructor != Array) {
			        params = [params];
			    }
			    $.each(params, function (i, n) {
			        source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
			    });
			    return source;
			};



export default {
	
	//get请求
    get (url,Method) {

      return new Promise((resolve,reject) => {
		  var url1 =$.format(url,Method);
			$.ajax({
			    type: "GET",
			    dataType: "json",
			    url: url1,
			    async:false
			}).then(res => {
          resolve(res)
        }).catch(err =>{
					reject(err)
				})
      })
    },
  //post请求
    post (url,params,Method) {
      return new Promise((resolve,reject) => {
				//		url=index_url+url
       var url1 =$.format(url,Method);
      			$.ajax({
      			    type: "POST",
      			    dataType: "json",
						url: url1,
					 data: params,
					contentType: 'application/json; charset=utf-8',
					async: false//非异步
      			}).then(res => {
          resolve(res)
        }).catch(err =>{
      					reject(err)
      				})
      })
     }
  }
	
	
